#!/usr/bin/python
# -*- coding: utf-8 -*-

# This source code is provided for testing/debuging purpose ;)

import PyNUT
import sys

if __name__ == "__main__" :

    print( "PyNUT test..." )
    #nut    = PyNUT.PyNUTClient( debug=True )
    nut    = PyNUT.PyNUTClient( host='raspionduleurs', port=3493 ,login="admin", password="pass", debug=True )

    print( 80*"-" + "\nTesting 'GetUPSList' :")
    result = nut.GetUPSList( )
    print( "\033[01;33m%s\033[0m\n" % result )

    print( 80*"-" + "\nTesting 'GetUPSVars' :")
    result = nut.GetUPSVars('ETX1500-test')
    print( "\033[01;33m%s\033[0m\n" % result )

    print( 80*"-" + "\nTesting 'GetUPSCommands' :")
    result = nut.GetUPSCommands('ETX1500-test')
    print( "\033[01;33m%s\033[0m\n" % result )

    print( 80*"-" + "\nTesting 'GetRWVars' :")
    result = nut.GetRWVars( 'ETX1500-test' )
    print( "\033[01;33m%s\033[0m\n" % result )

    print( 80*"-" + "\nTesting 'RunUPSCommand' (Test front panel) :")
    try :
        result = nut.RunUPSCommand( 'ETX1500-test', "test.panel.start" )
    except :
        result = sys.exc_info()[1]
    print( "\033[01;33m%s\033[0m\n" % result )

    print( 80*"-" + "\nTesting 'SetUPSVar' (set ups.id to test):")
    try :
        result = nut.SetRWVar( 'ETX1500-test', "ups.id", "test" )
    except :
        result = sys.exc_info()[1]
    print( "\033[01;33m%s\033[0m\n" % result )
    
    
    print( 80*"-" + "\nTesting 'RunUPSCommand' (Test battery) :")
    try :
        result = nut.RunUPSCommand( 'ETX1500-test', "test.battery.start.deep" )
    except :
        result = sys.exc_info()[1]
    print( "\033[01;33m%s\033[0m\n" % result )
    
